package com.qqtech.qquan.sms.service;

import java.sql.Timestamp;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import com.qqtech.core.common.enums.UserChannelEnum;
import com.qqtech.core.common.enums.YesNoEnum;
import com.qqtech.core.common.util.StringUtil;
import com.qqtech.core.common.util.TimeUtil;
import com.qqtech.core.frame.dao.BaseDao;
import com.qqtech.core.frame.service.BaseServiceImpl;
import com.qqtech.qquan.community.model.CommunityBase;
import com.qqtech.qquan.community.service.CommunityBaseService;
import com.qqtech.qquan.homemaking.model.HomemakingOrder;
import com.qqtech.qquan.homemaking.service.HomemakingOrderService;
import com.qqtech.qquan.mall.model.MallShop;
import com.qqtech.qquan.mall.service.MallShopService;
import com.qqtech.qquan.order.cache.OrderSysParamCache;
import com.qqtech.qquan.order.enums.OrderBaseDeliveryStatusSignTypeDictEnum;
import com.qqtech.qquan.order.enums.OrderBaseOrderTypeDictEnum;
import com.qqtech.qquan.order.enums.OrderBasePayStatusDictEnum;
import com.qqtech.qquan.order.enums.OrderBaseReturnStatusCompleteTypeDictEnum;
import com.qqtech.qquan.order.enums.OrderConst;
import com.qqtech.qquan.order.enums.OrderDeliveryTypeDictEnum;
import com.qqtech.qquan.order.enums.ReturnPayStatusAgreeTypeEnum;
import com.qqtech.qquan.order.model.OrderBase;
import com.qqtech.qquan.order.model.OrderDelivery;
import com.qqtech.qquan.order.model.OrderItem;
import com.qqtech.qquan.order.model.OrderSplit;
import com.qqtech.qquan.order.service.OrderBaseService;
import com.qqtech.qquan.order.service.OrderDeliveryService;
import com.qqtech.qquan.order.service.OrderItemService;
import com.qqtech.qquan.order.service.OrderSplitService;
import com.qqtech.qquan.send.enums.SendDeliveryUserAuditStatusDictEnum;
import com.qqtech.qquan.send.model.SendDeliveryUser;
import com.qqtech.qquan.send.model.SendDeliveryUserOrder;
import com.qqtech.qquan.send.service.SendDeliveryUserOrderService;
import com.qqtech.qquan.send.service.SendDeliveryUserService;
import com.qqtech.qquan.sms.dao.SmsBaseDao;
import com.qqtech.qquan.sms.helper.SmsCfg;
import com.qqtech.qquan.sms.model.SmsBase;
import com.qqtech.qquan.sys.cache.SysParamCache;
import com.qqtech.qquan.sys.enums.SysConst;
import com.qqtech.qquan.user.enums.UserIdentityTypeDictEnum;
import com.qqtech.qquan.user.model.UserAuth;
import com.qqtech.qquan.user.model.UserBase;
import com.qqtech.qquan.user.model.UserIdentity;
import com.qqtech.qquan.user.service.UserAuthService;
import com.qqtech.qquan.user.service.UserBaseService;
import com.qqtech.qquan.user.service.UserIdentityService;

@Service
public class SmsBizzServiceImpl extends BaseServiceImpl<SmsBase> implements SmsBizzService {
	public static final Logger log = LoggerFactory.getLogger(SmsBizzServiceImpl.class);
	@Resource
	private UserIdentityService userIdentityService;
	@Resource
	private UserBaseService userBaseService;
	@Resource
	private OrderBaseService orderBaseService;
	@Resource
	private SmsBaseService smsBaseService;
	@Resource
	private SmsBaseDao smsBaseDao;
	@Resource
	private HomemakingOrderService homemakingOrderService;
	@Resource
	private OrderDeliveryService orderDeliveryService;
	@Resource
	private OrderSysParamCache orderSysParamCache;
	@Resource
	private OrderSplitService orderSplitService;
	@Resource
	private SendDeliveryUserService sendDeliveryUserService;
	@Resource
	private SendDeliveryUserOrderService sendDeliveryUserOrderService;
	@Resource
	private UserAuthService userAuthService;
	@Resource
	private SysParamCache sysParamCache;
	@Resource
	private MallShopService mallShopService;
	@Resource
	private CommunityBaseService communityBaseService;
	@Resource
	private OrderItemService orderItemService;

	@Override
	protected BaseDao<SmsBase> getBaseDao() {
		return smsBaseDao;
	}

	/**
	 * 根据订单号获取该订单的产品、收货等信息(针对圈商)
	 * 
	 * @param orderNo
	 * @return
	 */
	private Map<String, String> getParamsByOrderNo(String orderNo) {
		if (StringUtil.isNotBlank(orderNo)) {
			OrderBase orderBase = orderBaseService.getByOrderNo(orderNo);
			if (orderBase != null) {
				Map<String, String> map = new HashMap<String, String>(8);
				String userName = "(未知)";
				String receiveName = "(未知)";
				String receiveAddress = "(自提)";
				String timeStr = "(未知)";
				String shopName = "(未知)";
				String productAndQuantity = "(未知)";
				String note = "(无)";
				UserBase userBase = userBaseService.getById(orderBase.getBuyerId());
				if (userBase != null && StringUtil.isNotBlank(userBase.getNick())) {
					userName = userBase.getNick();
				}
				if (orderBase.getPayStatusAt() != null) {
					timeStr = TimeUtil.getStringTimeByFormat(orderBase.getPayStatusAt(), "MM月dd日HH时mm分");
				} else {
					timeStr = TimeUtil.getStringTimeByFormat(orderBase.getNewAt(), "MM月dd日HH时mm分");
				}
				if (orderBase.getShopId() != null && orderBase.getShopId().intValue() != 0) {
					MallShop mallShop = mallShopService.getById(orderBase.getShopId());
					if (mallShop != null && StringUtil.isNotBlank(mallShop.getName())) {
						shopName = mallShop.getName();
					}
				}
				if (StringUtil.isNotBlank(orderBase.getRemark())) {
					note = orderBase.getRemark();
				}
				OrderItem orderItem = new OrderItem();
				orderItem.setOrderNo(orderNo);
				List<OrderItem> listOrderItem = orderItemService.queryList(orderItem);
				if (listOrderItem != null && listOrderItem.size() > 0) {
					StringBuffer sb = new StringBuffer("");
					for (OrderItem orderItem2 : listOrderItem) {
						if (StringUtil.isNotBlank(sb.toString())) {
							sb.append(",");
						}
						sb.append(orderItem2.getName()).append("x").append(orderItem2.getQuntity());
					}
					if (StringUtil.isNotBlank(sb.toString())) {
						productAndQuantity = sb.toString();
					}
				}
				OrderDelivery orderDelivery = orderDeliveryService.getByOrderNoAndType(orderNo,
						OrderDeliveryTypeDictEnum.SELLERSEND.getCode());
				if (orderDelivery != null) {
					if (StringUtil.isNotBlank(orderDelivery.getConsignee())) {
						receiveName = orderDelivery.getConsignee();
					}
					if (StringUtil.isNotBlank(orderDelivery.getPhone())) {
						receiveName = receiveName + "-"+orderDelivery.getPhone();
					}
					if (orderDelivery.getType() != null
							&& OrderDeliveryTypeDictEnum.BUYERPICKUP.getCode() == orderDelivery.getType().intValue()) {
						receiveAddress = "(自提)";
					} else {
						if (StringUtil.isNotBlank(orderDelivery.getAddress())) {
							receiveAddress = orderDelivery.getAddress();
						}
					}
				}
				map.put("orderNo", orderNo);
				map.put("userName", userName);
				map.put("receiveName", receiveName);
				map.put("receiveAddress", receiveAddress);
				map.put("timeStr", timeStr);
				map.put("shopName", shopName);
				map.put("productAndQuantity", productAndQuantity);
				map.put("note", note);
				map.put("sendTime", "半小时内");
				return map;
			}
		}
		return null;
	}

	@Override
	public void refuseReturnPay(String orderNo) {
		if (StringUtil.isBlank(orderNo)) {
			return;
		}
		OrderBase orderBase = orderBaseService.getByOrderNo(orderNo);
		if (orderBase == null || orderBase.getBuyerId() == null || orderBase.getBuyerId().intValue() == 0) {
			return;
		}
		UserIdentity userIdentity = new UserIdentity();
		userIdentity.setType(UserIdentityTypeDictEnum.PHONE.getCode());
		userIdentity.setUserId(orderBase.getBuyerId());
		userIdentity = userIdentityService.getOne(userIdentity);
		if (userIdentity == null) {
			return;
		}
		String userName = "";
		String phone = "";
		OrderSplit orderSplit = new OrderSplit();
		orderSplit.setOrderNo(orderNo);
		List<OrderSplit> listOrderSplit = orderSplitService.queryList(orderSplit);
		if (listOrderSplit != null && listOrderSplit.size() > 0) {
			for (OrderSplit orderSplit2 : listOrderSplit) {
				if (orderSplit2.getSellerId() != null && orderSplit2.getSellerId().intValue() != 0) {
					UserIdentity userIdentity1 = new UserIdentity();
					userIdentity1.setType(UserIdentityTypeDictEnum.PHONE.getCode());
					userIdentity1.setUserId(orderSplit2.getSellerId());
					userIdentity1 = userIdentityService.getOne(userIdentity1);
					if (userIdentity1 != null) {
						phone = userIdentity1.getIdentity();
						UserBase userBase = userBaseService.getById(orderSplit2.getSellerId());
						if (StringUtil.isNotBlank(userBase.getNick())) {
							userName = userBase.getNick();
						}
						break;
					}
				}
			}
		}
		Map<String, String> params = new HashMap<String, String>();
		params.put("userName", userName);
		params.put("phone", phone);
		params.put("orderNo", orderNo);
		params.put("qqphone", sysParamCache.get(SysConst.PARAM_SYS_CUSTOMER_PHONE, "18948328120"));
		smsBaseService.send(userIdentity.getIdentity(),
				SmsCfg.getInstance().getIntValue("sms.template.order.returnPayRefuse", 1030), params);
	}

	@Override
	public void agreeReturnPay(String orderNo, ReturnPayStatusAgreeTypeEnum returnPayStatusAgreeType) {
		if (StringUtil.isBlank(orderNo)) {
			return;
		}
		OrderBase orderBase = orderBaseService.getByOrderNo(orderNo);
		if (orderBase == null || orderBase.getBuyerId() == null || orderBase.getBuyerId().intValue() == 0) {
			return;
		}
		UserIdentity userIdentity = new UserIdentity();
		userIdentity.setType(UserIdentityTypeDictEnum.PHONE.getCode());
		userIdentity.setUserId(orderBase.getBuyerId());
		userIdentity = userIdentityService.getOne(userIdentity);
		if (userIdentity == null) {
			return;
		}
		String userName = "卖家";
		Map<String, String> params = new HashMap<String, String>();
		if (ReturnPayStatusAgreeTypeEnum.ADMIN.equals(returnPayStatusAgreeType)) {
			userName = "圈圈平台";
		}
		params.put("userName", userName);
		params.put("orderNo", orderNo);
		smsBaseService.send(userIdentity.getIdentity(),
				SmsCfg.getInstance().getIntValue("sms.template.order.returnPayAgree", 1029), params);
	}

	/**
	 * 根据订单号获取店铺电话，如无则返回空字符串
	 */
	private String getShopPhone(Integer shopId) {
		if (shopId != null && shopId.intValue() != 0 && shopId.intValue() != 1) {
			MallShop mallShop = mallShopService.getById(shopId);
			if (mallShop != null && StringUtil.isNotBlank(mallShop.getPhone())
					&& StringUtil.isPhone(mallShop.getPhone())) {
				return mallShop.getPhone();
			}
		}
		return "";
	}

	@Override
	public void applyReturnPay(String orderNo) {
		if (StringUtil.isBlank(orderNo)) {
			return;
		}
		OrderBase orderBase = orderBaseService.getByOrderNo(orderNo);
		if (orderBase == null) {
			return;
		}
		UserBase userBase = userBaseService.getById(orderBase.getBuyerId());
		String nick = "买家";
		if (StringUtil.isNotBlank(userBase.getNick())) {
			nick = userBase.getNick();
		}
		UserIdentity userIdentity1 = new UserIdentity();
		userIdentity1.setType(UserIdentityTypeDictEnum.PHONE.getCode());
		userIdentity1.setUserId(orderBase.getBuyerId());
		userIdentity1 = userIdentityService.getOne(userIdentity1);
		if (userIdentity1 == null) {
			return;
		}
		String toShopPhone = getShopPhone(orderBase.getShopId());
		if (StringUtil.isNotBlank(toShopPhone)) {
			Map<String, String> params = new HashMap<String, String>();
			params.put("userName", nick);
			params.put("phone", userIdentity1.getIdentity());
			params.put("orderNo", orderNo);
			smsBaseService.send(toShopPhone,
					SmsCfg.getInstance().getIntValue("sms.template.order.returnPayApply", 1028), params);
		} else {
			OrderSplit orderSplit = new OrderSplit();
			orderSplit.setOrderNo(orderNo);
			List<OrderSplit> listOrderSplit = orderSplitService.queryList(orderSplit);
			if (listOrderSplit != null && listOrderSplit.size() > 0) {
				for (OrderSplit orderSplit2 : listOrderSplit) {
					if (orderSplit2.getSellerId() != null && orderSplit2.getSellerId().intValue() != 0) {
						UserIdentity userIdentity = new UserIdentity();
						userIdentity.setType(UserIdentityTypeDictEnum.PHONE.getCode());
						userIdentity.setUserId(orderSplit2.getSellerId());
						userIdentity = userIdentityService.getOne(userIdentity);
						if (userBase == null || userIdentity == null || (userIdentity.getType() != null
								&& UserIdentityTypeDictEnum.PHONE.getCode() != userIdentity.getType())) {
							continue;
						}
						Map<String, String> params = new HashMap<String, String>();
						params.put("userName", nick);
						params.put("phone", userIdentity1.getIdentity());
						params.put("orderNo", orderNo);
						smsBaseService.send(userIdentity.getIdentity(),
								SmsCfg.getInstance().getIntValue("sms.template.order.returnPayApply", 1028), params);
					}
				}
			}
		}
	}

	@Override
	public void realAuth(Integer userId, YesNoEnum yesNo) {
		if (userId == null || userId.intValue() == 0 || yesNo == null) {
			return;
		}
		UserIdentity userIdentity = new UserIdentity();
		userIdentity.setType(UserIdentityTypeDictEnum.PHONE.getCode());
		userIdentity.setUserId(userId);
		List<UserIdentity> userIdentityList = userIdentityService.queryList(userIdentity);
		if (userIdentityList == null || userIdentityList.size() == 0) {
			return;
		}
		userIdentity = userIdentityList.get(0);
		Map<String, String> params = new HashMap<String, String>();
		if (YesNoEnum.YES.getCode() == yesNo.getCode()) {
			smsBaseService.send(userIdentity.getIdentity(),
					SmsCfg.getInstance().getIntValue("sms.template.user.auth.ok", 1022), params);
		} else {
			smsBaseService.send(userIdentity.getIdentity(),
					SmsCfg.getInstance().getIntValue("sms.template.user.auth.reject", 1021), params);
		}
	}

	@Override
	public void applyReturn(String orderNo) {
		if (StringUtil.isBlank(orderNo)) {
			return;
		}
		OrderBase orderBase = orderBaseService.getByOrderNo(orderNo);
		if (orderBase == null) {
			return;
		}
		UserBase userBase = userBaseService.getById(orderBase.getBuyerId());
		String nick = "买家";
		if (StringUtil.isNotBlank(userBase.getNick())) {
			nick = userBase.getNick();
		}
		String toShopPhone = getShopPhone(orderBase.getShopId());
		if (StringUtil.isNotBlank(toShopPhone)) {
			Map<String, String> params = new HashMap<String, String>();
			params.put("userName", nick);
			smsBaseService.send(toShopPhone, SmsCfg.getInstance().getIntValue("sms.template.order.applyReturn", 1008),
					params);
		} else {
			OrderSplit orderSplit = new OrderSplit();
			orderSplit.setOrderNo(orderNo);
			List<OrderSplit> listOrderSplit = orderSplitService.queryList(orderSplit);
			if (listOrderSplit != null && listOrderSplit.size() > 0) {
				for (OrderSplit orderSplit2 : listOrderSplit) {
					if (orderSplit2.getSellerId() != null && orderSplit2.getSellerId().intValue() != 0) {
						UserIdentity userIdentity = new UserIdentity();
						userIdentity.setType(UserIdentityTypeDictEnum.PHONE.getCode());
						userIdentity.setUserId(orderSplit2.getSellerId());
						userIdentity = userIdentityService.getOne(userIdentity);
						if (userBase == null || userIdentity == null || (userIdentity.getType() != null
								&& UserIdentityTypeDictEnum.PHONE.getCode() != userIdentity.getType())) {
							continue;
						}
						Map<String, String> params = new HashMap<String, String>();
						params.put("userName", nick);
						smsBaseService.send(userIdentity.getIdentity(),
								SmsCfg.getInstance().getIntValue("sms.template.order.applyReturn", 1008), params);
					}
				}
			}
		}
	}

	@Override
	public void returned(String orderNo, OrderBaseReturnStatusCompleteTypeDictEnum orderBaseReturnStatusCompleteType) {
		if (StringUtil.isBlank(orderNo)) {
			return;
		}
		OrderBase orderBase = orderBaseService.getByOrderNo(orderNo);
		if (orderBase == null || orderBase.getBuyerId() == null || orderBase.getBuyerId().intValue() == 0) {
			return;
		}
		UserIdentity userIdentity = new UserIdentity();
		userIdentity.setType(UserIdentityTypeDictEnum.PHONE.getCode());
		userIdentity.setUserId(orderBase.getBuyerId());
		userIdentity = userIdentityService.getOne(userIdentity);
		if (userIdentity == null || (userIdentity.getType() != null
				&& UserIdentityTypeDictEnum.PHONE.getCode() != userIdentity.getType())) {
			return;
		}
		Map<String, String> params = new HashMap<String, String>();
		if (OrderBaseReturnStatusCompleteTypeDictEnum.AUTORETURNED.equals(orderBaseReturnStatusCompleteType)) {
			params.put("orderNo", orderBase.getOrderNo());
			params.put("x", orderSysParamCache.get(OrderConst.DICTYPE_ORDER_ONLINE_REFUND_AUTO_EXPIRE_DAYS, "3"));
			smsBaseService.send(userIdentity.getIdentity(),
					SmsCfg.getInstance().getIntValue("sms.template.order.autoReturn1", 1020), params);
		} else {
			smsBaseService.send(userIdentity.getIdentity(),
					SmsCfg.getInstance().getIntValue("sms.template.order.returned", 1009), params);
		}
	}

	@Override
	public void buyerCancel(String orderNo) {
		if (StringUtil.isBlank(orderNo)) {
			return;
		}
		OrderBase orderBase = orderBaseService.getByOrderNo(orderNo);
		if (orderBase == null) {
			return;
		}
		UserBase userBase = userBaseService.getById(orderBase.getBuyerId());
		String nick = "买家";
		if (StringUtil.isNotBlank(userBase.getNick())) {
			nick = userBase.getNick();
		}
		String toShopPhone = getShopPhone(orderBase.getShopId());
		if (StringUtil.isNotBlank(toShopPhone)) {
			Map<String, String> params = new HashMap<String, String>();
			params.put("userName", nick);
			smsBaseService.send(toShopPhone, SmsCfg.getInstance().getIntValue("sms.template.order.buyercancel", 1006),
					params);
		} else {
			OrderSplit orderSplit = new OrderSplit();
			orderSplit.setOrderNo(orderNo);
			List<OrderSplit> listOrderSplit = orderSplitService.queryList(orderSplit);
			if (listOrderSplit != null && listOrderSplit.size() > 0) {
				for (OrderSplit orderSplit2 : listOrderSplit) {
					if (orderSplit2.getSellerId() != null && orderSplit2.getSellerId().intValue() != 0) {
						UserIdentity userIdentity = new UserIdentity();
						userIdentity.setType(UserIdentityTypeDictEnum.PHONE.getCode());
						userIdentity.setUserId(orderSplit2.getSellerId());
						userIdentity = userIdentityService.getOne(userIdentity);
						if (userBase == null || userIdentity == null || (userIdentity.getType() != null
								&& UserIdentityTypeDictEnum.PHONE.getCode() != userIdentity.getType())) {
							continue;
						}
						Map<String, String> params = new HashMap<String, String>();
						params.put("userName", nick);
						smsBaseService.send(userIdentity.getIdentity(),
								SmsCfg.getInstance().getIntValue("sms.template.order.buyercancel", 1006), params);
					}
				}
			}
		}
		if (orderBase.getPayStatus() != null
				&& OrderBasePayStatusDictEnum.UNPAYED.getCode() != orderBase.getPayStatus().intValue()) {
			if (orderBase.getIsExternal() != null && YesNoEnum.NO.getCode() == orderBase.getIsExternal()
					&& OrderBaseOrderTypeDictEnum.QUANMALL.getCode() == orderBase.getOrderType().intValue()) {
				OrderDelivery orderDelivery = orderDeliveryService.getByOrderNo(orderNo);
				if (orderDelivery != null && orderDelivery.getType() != null
						&& OrderDeliveryTypeDictEnum.BUYERPICKUP.getCode() != orderDelivery.getType().intValue()) {
					// 同时短信通知给配送方接口人
					Map<String, String> paramsCharge = new HashMap<String, String>();
					paramsCharge.put("orderNo", orderBase.getOrderNo());
					paramsCharge.put("userInfo", nick);
					paramsCharge.put("bizzType", "社区商品");
					paramsCharge.put("bizzContent", orderBase.getTitle());
					SendDeliveryUserOrder sendDeliveryUserOrder = sendDeliveryUserOrderService.getByOrderNo(orderNo);
					if (sendDeliveryUserOrder != null) {
						UserIdentity userIdentity = new UserIdentity();
						userIdentity.setUserId(sendDeliveryUserOrder.getDeliveryUserId());
						userIdentity.setType(UserChannelEnum.PHONE.getCode());
						userIdentity = userIdentityService.getOne(userIdentity);
						if (userIdentity != null) {
							smsBaseService.send(userIdentity.getIdentity(),
									SmsCfg.getInstance().getIntValue("sms.template.order.cancel", 1026), paramsCharge);
						}
					}
					// 同时短信通知给超级权限配送人
					SendDeliveryUser sendDeliveryUser = new SendDeliveryUser();
					sendDeliveryUser.setHasSuperPower(YesNoEnum.YES.getCode());
					List<SendDeliveryUser> listSendDeliveryUser = sendDeliveryUserService.queryList(sendDeliveryUser);
					if (listSendDeliveryUser != null && listSendDeliveryUser.size() > 0) {
						for (SendDeliveryUser sendDeliveryUser2 : listSendDeliveryUser) {
							UserIdentity identity = new UserIdentity();
							identity.setUserId(sendDeliveryUser2.getUserId());
							identity.setType(UserIdentityTypeDictEnum.PHONE.getCode());
							List<UserIdentity> listUserIdentity = userIdentityService.queryList(identity);
							if (listUserIdentity != null && listUserIdentity.size() > 0) {
								for (UserIdentity userIdentity : listUserIdentity) {
									smsBaseService.send(userIdentity.getIdentity(),
											SmsCfg.getInstance().getIntValue("sms.template.order.cancel", 1026),
											paramsCharge);
								}
							}
						}
					}
				}
			}
		}
	}

	@Override
	public void sellerCancel(String orderNo) {
		if (StringUtil.isBlank(orderNo)) {
			return;
		}
		OrderBase orderBase = orderBaseService.getByOrderNo(orderNo);
		if (orderBase == null || orderBase.getBuyerId() == null || orderBase.getBuyerId().intValue() == 0) {
			return;
		}
		UserIdentity userIdentity = new UserIdentity();
		userIdentity.setType(UserIdentityTypeDictEnum.PHONE.getCode());
		userIdentity.setUserId(orderBase.getBuyerId());
		userIdentity = userIdentityService.getOne(userIdentity);
		if (userIdentity == null || (userIdentity.getType() != null
				&& UserIdentityTypeDictEnum.PHONE.getCode() != userIdentity.getType())) {
			return;
		}
		Map<String, String> params = new HashMap<String, String>();
		smsBaseService.send(userIdentity.getIdentity(),
				SmsCfg.getInstance().getIntValue("sms.template.order.sellercancel", 1007), params);
	}

	@Override
	public void orderSigned(String orderNo, OrderBaseDeliveryStatusSignTypeDictEnum orderBaseDeliveryStatusSignType) {
		if (StringUtil.isBlank(orderNo)) {
			return;
		}
		OrderBase orderBase = orderBaseService.getByOrderNo(orderNo);
		if (orderBase == null) {
			return;
		}
		UserBase userBase = userBaseService.getById(orderBase.getBuyerId());
		String toShopPhone = getShopPhone(orderBase.getShopId());
		OrderSplit orderSplit = new OrderSplit();
		orderSplit.setOrderNo(orderNo);
		List<OrderSplit> listOrderSplit = orderSplitService.queryList(orderSplit);
		if (listOrderSplit != null && listOrderSplit.size() > 0) {
			for (OrderSplit orderSplit2 : listOrderSplit) {
				if (orderSplit2.getSellerId() != null && orderSplit2.getSellerId().intValue() != 0) {
					UserIdentity userIdentity = new UserIdentity();
					userIdentity.setType(UserIdentityTypeDictEnum.PHONE.getCode());
					userIdentity.setUserId(orderSplit2.getSellerId());
					userIdentity = userIdentityService.getOne(userIdentity);
					if (userBase == null || userIdentity == null || (userIdentity.getType() != null
							&& UserIdentityTypeDictEnum.PHONE.getCode() != userIdentity.getType())) {
						continue;
					}
					String nick = "";
					if (StringUtil.isNotBlank(userBase.getNick())) {
						nick = userBase.getNick();
					}
					Map<String, String> params = new HashMap<String, String>();
					if (OrderBaseDeliveryStatusSignTypeDictEnum.AUTOSIGNED.equals(orderBaseDeliveryStatusSignType)) {
						params.put("orderNo", orderBase.getOrderNo());
						params.put("x",
								orderSysParamCache.get(OrderConst.DICTYPE_ORDER_ONLINE_RECEIVE_AUTO_EXPIRE_DAYS, "7"));
						if (StringUtil.isNotBlank(toShopPhone)) {
							smsBaseService.send(toShopPhone,
									SmsCfg.getInstance().getIntValue("sms.template.order.autoSign", 1018), params);
						} else {
							smsBaseService.send(userIdentity.getIdentity(),
									SmsCfg.getInstance().getIntValue("sms.template.order.autoSign", 1018), params);
						}
					} else {
						if (OrderBaseOrderTypeDictEnum.HOMEMAKING.getCode() == orderBase.getOrderType().intValue()) {
							params.put("userName", nick);
							smsBaseService.send(userIdentity.getIdentity(),
									SmsCfg.getInstance().getIntValue("sms.template.order.homemakingBuyerSign", 1017),
									params);
						} else {
							params.put("userName", nick);
							if (StringUtil.isNotBlank(toShopPhone)) {
								smsBaseService.send(toShopPhone,
										SmsCfg.getInstance().getIntValue("sms.template.order.signed", 1005), params);
							} else {
								smsBaseService.send(userIdentity.getIdentity(),
										SmsCfg.getInstance().getIntValue("sms.template.order.signed", 1005), params);
							}
						}
					}
				}
			}
		}
	}

	@Override
	public void orderSent(String orderNo) {
		if (StringUtil.isBlank(orderNo)) {
			return;
		}
		OrderBase orderBase = orderBaseService.getByOrderNo(orderNo);
		if (orderBase == null || orderBase.getBuyerId() == null || orderBase.getBuyerId().intValue() == 0) {
			return;
		}
		UserIdentity userIdentity = new UserIdentity();
		userIdentity.setType(UserIdentityTypeDictEnum.PHONE.getCode());
		userIdentity.setUserId(orderBase.getBuyerId());
		userIdentity = userIdentityService.getOne(userIdentity);
		if (userIdentity == null || (userIdentity.getType() != null
				&& UserIdentityTypeDictEnum.PHONE.getCode() != userIdentity.getType())) {
			return;
		}
		Map<String, String> params = new HashMap<String, String>();
		if (OrderBaseOrderTypeDictEnum.HOMEMAKING.getCode() == orderBase.getOrderType().intValue()) {
			String title = "服务";
			if (StringUtil.isNotBlank(orderBase.getTitle())) {
				title = orderBase.getTitle();
			}
			params.put("title", title);
			smsBaseService.send(userIdentity.getIdentity(),
					SmsCfg.getInstance().getIntValue("sms.template.order.homemakingSellerFinish", 1016), params);
		} else {
			smsBaseService.send(userIdentity.getIdentity(),
					SmsCfg.getInstance().getIntValue("sms.template.order.sent", 1004), params);
			// 同时通知对应社区的顶级配送人员
			this.orderSentToTopdelivery(orderNo);
		}
	}

	/**
	 * 商家发货时通知社区对应的顶级配送人员
	 * 
	 * @param orderNo
	 */
	public void orderSentToTopdelivery(String orderNo) {
		if (StringUtil.isBlank(orderNo)) {
			return;
		}
		OrderBase orderBase = orderBaseService.getByOrderNo(orderNo);
		if (orderBase == null || orderBase.getCommunityId() == null || orderBase.getCommunityId().intValue() == 0) {
			return;
		}
		UserBase userBase = userBaseService.getById(orderBase.getBuyerId());
		if (userBase == null) {
			return;
		}
		UserIdentity userBuyerIdentity = new UserIdentity();
		userBuyerIdentity.setType(UserIdentityTypeDictEnum.PHONE.getCode());
		userBuyerIdentity.setUserId(orderBase.getBuyerId());
		userBuyerIdentity = userIdentityService.getOne(userBuyerIdentity);
		String buyerPhone = "(无)";
		if (userBuyerIdentity != null && UserIdentityTypeDictEnum.PHONE.getCode() == userBuyerIdentity.getType()) {
			buyerPhone = userBuyerIdentity.getIdentity();
		}
		String nick = "买家";
		if (StringUtil.isNotBlank(userBase.getNick())) {
			nick = userBase.getNick();
		}
		String orderTimeStr = TimeUtil.getStringTimeByFormat(orderBase.getNewAt(), "MM月dd日HH时mm分");
		// 短信通知给配送方顶级接口人
		if (orderBase.getOrderType() != null
				&& OrderBaseOrderTypeDictEnum.QSHOP.getCode() == orderBase.getOrderType().intValue()) {
			Map<String, String> paramsCharge = new HashMap<String, String>();
			OrderDelivery orderDelivery = orderDeliveryService.getByOrderNoAndType(orderNo,
					OrderDeliveryTypeDictEnum.SELLERSEND.getCode());
			if (orderDelivery == null) {
				orderDelivery = orderDeliveryService.getByOrderNo(orderNo);
			}
			String tips = "";
			if (orderDelivery != null) {
				if (orderDelivery.getType() != null
						&& OrderDeliveryTypeDictEnum.BUYERPICKUP.getCode() == orderDelivery.getType().intValue()) {
					tips = "(自提)";
				}
				paramsCharge.put("userInfo", "(" + nick + "," + buyerPhone + "," + orderDelivery.getAddress() + ")");
			} else {
				paramsCharge.put("userInfo", "(" + nick + "," + buyerPhone + ")");
			}
			String shopInfo = "社区店铺";
			if (orderBase.getShopId() != null && orderBase.getShopId().intValue() != 0) {
				MallShop mallShop = mallShopService.getById(orderBase.getShopId());
				if (mallShop != null) {
					shopInfo = mallShop.getName();
					if (StringUtil.isNotBlank(mallShop.getPhone())) {
						shopInfo = shopInfo + "," + mallShop.getPhone();
					}
				}
			}
			paramsCharge.put("orderTime", orderTimeStr);
			paramsCharge.put("bizzType", "社区");
			paramsCharge.put("bizzContent", "(" + shopInfo + "--" + orderBase.getTitle() + ")" + tips);
			if (StringUtil.isBlank(tips)) {// 如果不是自提，则短信提醒配送方
				SendDeliveryUser sendDeliveryUser = new SendDeliveryUser();
				sendDeliveryUser.setCommunityId(orderBase.getCommunityId());
				sendDeliveryUser.setStatus(YesNoEnum.YES.getCode());
				sendDeliveryUser.setAuditStatus(SendDeliveryUserAuditStatusDictEnum.THROUGH.getCode());
				sendDeliveryUser.setParentId(0);
				List<SendDeliveryUser> listSendDeliveryUser = sendDeliveryUserService.queryList(sendDeliveryUser);
				if (listSendDeliveryUser == null || listSendDeliveryUser.size() == 0) {
					return;
				}
				sendDeliveryUser = listSendDeliveryUser.get(0);
				// 同时短信通知给配送方顶级接口人
				if (sendDeliveryUser != null) {
					UserIdentity userIdentity = new UserIdentity();
					userIdentity.setUserId(sendDeliveryUser.getUserId());
					userIdentity.setType(UserChannelEnum.PHONE.getCode());
					userIdentity = userIdentityService.getOne(userIdentity);
					if (userIdentity != null) {
						smsBaseService.send(userIdentity.getIdentity(),
								SmsCfg.getInstance().getIntValue("sms.template.order.notice.sendToCharge", 1025),
								paramsCharge);
					}
				}
			}
		}
	}

	@Override
	public void orderPayedOrOndelivery(String orderNo) {
		if (StringUtil.isBlank(orderNo)) {
			return;
		}
		OrderBase orderBase = orderBaseService.getByOrderNo(orderNo);
		if (orderBase == null) {
			return;
		}
		UserBase userBase = userBaseService.getById(orderBase.getBuyerId());
		if (userBase == null) {
			return;
		}
		UserIdentity userBuyerIdentity = new UserIdentity();
		userBuyerIdentity.setType(UserIdentityTypeDictEnum.PHONE.getCode());
		userBuyerIdentity.setUserId(orderBase.getBuyerId());
		userBuyerIdentity = userIdentityService.getOne(userBuyerIdentity);
		String buyerPhone = "(无)";
		if (userBuyerIdentity != null && UserIdentityTypeDictEnum.PHONE.getCode() == userBuyerIdentity.getType()) {
			buyerPhone = userBuyerIdentity.getIdentity();
		}
		String nick = "买家";
		if (StringUtil.isNotBlank(userBase.getNick())) {
			nick = userBase.getNick();
		}
		String orderTimeStr = TimeUtil.getStringTimeByFormat(orderBase.getNewAt(), "MM月dd日HH时mm分");
		OrderSplit orderSplit = new OrderSplit();
		orderSplit.setOrderNo(orderNo);
		List<OrderSplit> listOrderSplit = orderSplitService.queryList(orderSplit);
		String orderPhone = "";
		if (orderBase.getCommunityId() != null && orderBase.getCommunityId().intValue() != 0) {
			CommunityBase communityBase = communityBaseService.getById(orderBase.getCommunityId());
			if (communityBase != null && StringUtil.isNotBlank(communityBase.getOrderPhone())) {
				if (StringUtil.isPhone(communityBase.getOrderPhone())) {
					orderPhone = communityBase.getOrderPhone();
				}
			}
		}
		String shopPhone = getShopPhone(orderBase.getShopId());
		if (listOrderSplit != null && listOrderSplit.size() > 0) {
			for (OrderSplit orderSplit2 : listOrderSplit) {
				if (orderSplit2.getSellerId() != null && orderSplit2.getSellerId().intValue() != 0) {
					UserIdentity userIdentity = new UserIdentity();
					userIdentity.setType(UserIdentityTypeDictEnum.PHONE.getCode());
					userIdentity.setUserId(orderSplit2.getSellerId());
					userIdentity = userIdentityService.getOne(userIdentity);
					if (userIdentity == null || (userIdentity.getType() != null
							&& UserIdentityTypeDictEnum.PHONE.getCode() != userIdentity.getType())) {
						continue;
					}
					Map<String, String> params = new HashMap<String, String>();
					Map<String, String> paramsCharge = new HashMap<String, String>();

					if (OrderBaseOrderTypeDictEnum.HOMEMAKING.getCode() == orderBase.getOrderType().intValue()) {
						OrderDelivery orderDelivery = orderDeliveryService.getByOrderNoAndType(orderNo,
								OrderDeliveryTypeDictEnum.SELLERSERVICE.getCode());
						HomemakingOrder homemakingOrder = homemakingOrderService.getByOrderNo(orderNo);
						if (orderDelivery != null && homemakingOrder != null) {
							String timeStr = TimeUtil.getStringTimeByFormat(homemakingOrder.getServiceAt(),
									"MM月dd日HH时mm分");
							params.put("address", orderDelivery.getAddress());
							params.put("time", timeStr);
							params.put("service", orderBase.getTitle());
							params.put("userName", orderDelivery.getConsignee() + orderDelivery.getPhone());
							params.put("phone", buyerPhone);
							params.put("hour",
									orderSysParamCache.get(OrderConst.DICTYPE_ORDER_ONLINE_NOCANCEL_BEFORE_HOURS, "1"));
							smsBaseService.send(userIdentity.getIdentity(), SmsCfg.getInstance()
									.getIntValue("sms.template.order.homemakingPayedOrOndelivery", 1023), params);
							paramsCharge.put("userInfo",
									"(" + nick + "," + buyerPhone + "," + orderDelivery.getAddress() + ")");
							paramsCharge.put("orderTime", orderTimeStr);
							paramsCharge.put("bizzType", "服务");
							paramsCharge.put("bizzContent", "(" + orderBase.getTitle() + "," + timeStr + ","
									+ userIdentity.getIdentity() + ")");
							String toPhone = orderSysParamCache.get(OrderConst.PARAMKEY_ORDER_CHARGEPHONE_HOMEMAKING,
									"15100090304");
							if (StringUtil.isNotBlank(orderPhone)) {
								toPhone = orderPhone;
							}
							smsBaseService.send(toPhone,
									SmsCfg.getInstance().getIntValue("sms.template.order.notice.sendToCharge", 1025),
									paramsCharge);
						}
					} else if (OrderBaseOrderTypeDictEnum.ACTIVITY.getCode() == orderBase.getOrderType().intValue()) {
						params.put("userName", nick);
						params.put("title", orderBase.getTitle());
						smsBaseService.send(userIdentity.getIdentity(),
								SmsCfg.getInstance().getIntValue("sms.template.order.activityPayed", 1013), params);
					} else {
						Map<String, String> map = this.getParamsByOrderNo(orderNo);
						if (OrderBaseOrderTypeDictEnum.QUANMALL.getCode() == orderBase.getOrderType().intValue()) {
							if (map != null) {
								String toPhone = userIdentity.getIdentity();
								if (StringUtil.isNotBlank(shopPhone)) {
									toPhone = shopPhone;
								}
								// 通知给商家
								Map<String, String> shopParams = new HashMap<String, String>();
								shopParams.put("userName", map.get("userName"));
								shopParams.put("receiveName", map.get("receiveName"));
								shopParams.put("receiveAddress", map.get("receiveAddress"));
								shopParams.put("timeStr", map.get("timeStr"));
								shopParams.put("productAndQuantity", map.get("productAndQuantity"));
								smsBaseService.send(toPhone,
										SmsCfg.getInstance().getIntValue("sms.template.order.newPayedToSeller", 1033),
										shopParams);
								// 通知给圈圈
								Map<String, String> qqParams = new HashMap<String, String>();
								qqParams.put("userName", map.get("userName"));
								qqParams.put("receiveName", map.get("receiveName"));
								qqParams.put("receiveAddress", map.get("receiveAddress"));
								qqParams.put("timeStr", map.get("timeStr"));
								qqParams.put("shopName", map.get("shopName"));
								qqParams.put("productAndQuantity", map.get("productAndQuantity"));
								qqParams.put("note", map.get("note"));
								toPhone = orderSysParamCache.get(OrderConst.PARAMKEY_ORDER_CHARGEPHONE_QSHOP,
										"15100090304");
								if (StringUtil.isNotBlank(orderPhone)) {
									toPhone = orderPhone;
								}
								smsBaseService.send(toPhone, SmsCfg.getInstance()
										.getIntValue("sms.template.order.newPayedOrBeDelivery", 1031), qqParams);
							}
							/*
							 * OrderDelivery orderDelivery =
							 * orderDeliveryService.getByOrderNoAndType(orderNo,
							 * OrderDeliveryTypeDictEnum.SELLERSEND.getCode());
							 * if (orderDelivery == null) { orderDelivery =
							 * orderDeliveryService.getByOrderNo(orderNo); } if
							 * (orderDelivery != null) {
							 * paramsCharge.put("userInfo", "(" + nick + "," +
							 * buyerPhone + "," + orderDelivery.getAddress() +
							 * ")"); } else { paramsCharge.put("userInfo", "(" +
							 * nick + "," + buyerPhone + ")"); }
							 * paramsCharge.put("orderTime", orderTimeStr);
							 * paramsCharge.put("bizzType", "商城");
							 * paramsCharge.put("bizzContent", "(" +
							 * orderBase.getTitle() + ")");
							 * smsBaseService.send(toPhone,
							 * SmsCfg.getInstance().getIntValue(
							 * "sms.template.order.notice.sendToCharge", 1025),
							 * paramsCharge);
							 */
						} else if (OrderBaseOrderTypeDictEnum.QSHOP.getCode() == orderBase.getOrderType().intValue()) {
							if (map != null) {
								String toPhone = userIdentity.getIdentity();
								if (StringUtil.isNotBlank(shopPhone)) {
									toPhone = shopPhone;
								}
								// 通知给商家
								Map<String, String> shopParams = new HashMap<String, String>();
								shopParams.put("userName", map.get("userName"));
								shopParams.put("receiveName", map.get("receiveName"));
								shopParams.put("receiveAddress", map.get("receiveAddress"));
								shopParams.put("timeStr", map.get("timeStr"));
								shopParams.put("productAndQuantity", map.get("productAndQuantity"));
								smsBaseService.send(toPhone,
										SmsCfg.getInstance().getIntValue("sms.template.order.newPayedToSeller", 1033),
										shopParams);
								// 通知给圈圈
								Map<String, String> qqParams = new HashMap<String, String>();
								qqParams.put("userName", map.get("userName"));
								qqParams.put("receiveName", map.get("receiveName"));
								qqParams.put("receiveAddress", map.get("receiveAddress"));
								qqParams.put("timeStr", map.get("timeStr"));
								qqParams.put("shopName", map.get("shopName"));
								qqParams.put("productAndQuantity", map.get("productAndQuantity"));
								qqParams.put("note", map.get("note"));
								toPhone = orderSysParamCache.get(OrderConst.PARAMKEY_ORDER_CHARGEPHONE_QSHOP,
										"15100090304");
								if (StringUtil.isNotBlank(orderPhone)) {
									toPhone = orderPhone;
								}
								smsBaseService.send(toPhone, SmsCfg.getInstance()
										.getIntValue("sms.template.order.newPayedOrBeDelivery", 1031), qqParams);
								if (StringUtil.isNotBlank(buyerPhone)) {
									// 通知给用户
									Map<String, String> userParams = new HashMap<String, String>();
									userParams.put("shopName", map.get("shopName"));
									userParams.put("productAndQuantity", map.get("productAndQuantity"));
									userParams.put("sendTime", map.get("sendTime"));
									smsBaseService.send(buyerPhone,
											SmsCfg.getInstance().getIntValue("sms.template.order.newPayedToUser", 1034),
											userParams);
								}
							}
							/*
							 * OrderDelivery orderDelivery =
							 * orderDeliveryService.getByOrderNoAndType(orderNo,
							 * OrderDeliveryTypeDictEnum.SELLERSEND.getCode());
							 * if (orderDelivery == null) { orderDelivery =
							 * orderDeliveryService.getByOrderNo(orderNo); } if
							 * (orderDelivery != null) {
							 * paramsCharge.put("userInfo", "(" + nick + "," +
							 * buyerPhone + "," + orderDelivery.getAddress() +
							 * ")"); } else { paramsCharge.put("userInfo", "(" +
							 * nick + "," + buyerPhone + ")"); }
							 * paramsCharge.put("orderTime", orderTimeStr);
							 * paramsCharge.put("bizzType", "圈商");
							 * paramsCharge.put("bizzContent", "(" +
							 * orderBase.getTitle() + ")");
							 * 
							 * String toPhone =
							 * orderSysParamCache.get(OrderConst.
							 * PARAMKEY_ORDER_CHARGEPHONE_QSHOP, "15100090304");
							 * if (StringUtil.isNotBlank(orderPhone)) { toPhone
							 * = orderPhone; } smsBaseService.send(toPhone,
							 * SmsCfg.getInstance().getIntValue(
							 * "sms.template.order.notice.sendToCharge", 1025),
							 * paramsCharge);
							 */
						} else {
							params.put("userName", nick);
							params.put("title", orderBase.getTitle());
							String toShopPhone = getShopPhone(orderBase.getShopId());
							if (StringUtil.isNotBlank(toShopPhone)) {
								smsBaseService.send(toShopPhone,
										SmsCfg.getInstance().getIntValue("sms.template.order.payedCommon", 1012),
										params);
							} else {
								smsBaseService.send(userIdentity.getIdentity(),
										SmsCfg.getInstance().getIntValue("sms.template.order.payedCommon", 1012),
										params);
							}
						}
					}
				}
			}
		} else {
			if (orderBase.getSellerId() != null && orderBase.getSellerId().intValue() != 0) {
				UserIdentity userIdentity = new UserIdentity();
				userIdentity.setType(UserIdentityTypeDictEnum.PHONE.getCode());
				userIdentity.setUserId(orderBase.getSellerId());
				userIdentity = userIdentityService.getOne(userIdentity);
				if (userIdentity != null) {
					Map<String, String> params = new HashMap<String, String>();
					Map<String, String> paramsCharge = new HashMap<String, String>();
					if (OrderBaseOrderTypeDictEnum.HOMEMAKING.getCode() == orderBase.getOrderType().intValue()) {
						OrderDelivery orderDelivery = orderDeliveryService.getByOrderNoAndType(orderNo,
								OrderDeliveryTypeDictEnum.SELLERSERVICE.getCode());
						HomemakingOrder homemakingOrder = homemakingOrderService.getByOrderNo(orderNo);
						if (orderDelivery != null && homemakingOrder != null) {
							String timeStr = TimeUtil.getStringTimeByFormat(homemakingOrder.getServiceAt(),
									"MM月dd日HH时mm分");
							params.put("address", orderDelivery.getAddress());
							params.put("time", timeStr);
							params.put("service", orderBase.getTitle());
							params.put("userName", orderDelivery.getConsignee() + orderDelivery.getPhone());
							params.put("phone", buyerPhone);
							params.put("hour",
									orderSysParamCache.get(OrderConst.DICTYPE_ORDER_ONLINE_NOCANCEL_BEFORE_HOURS, "1"));
							smsBaseService.send(userIdentity.getIdentity(), SmsCfg.getInstance()
									.getIntValue("sms.template.order.homemakingPayedOrOndelivery", 1023), params);
							paramsCharge.put("userInfo",
									"(" + nick + "," + buyerPhone + "," + orderDelivery.getAddress() + ")");
							paramsCharge.put("orderTime", orderTimeStr);
							paramsCharge.put("bizzType", "服务");
							paramsCharge.put("bizzContent", "(" + orderBase.getTitle() + "," + timeStr + ","
									+ userIdentity.getIdentity() + ")");

							String toPhone = orderSysParamCache.get(OrderConst.PARAMKEY_ORDER_CHARGEPHONE_HOMEMAKING,
									"15100090304");
							if (StringUtil.isNotBlank(orderPhone)) {
								toPhone = orderPhone;
							}
							smsBaseService.send(toPhone,
									SmsCfg.getInstance().getIntValue("sms.template.order.notice.sendToCharge", 1025),
									paramsCharge);
						}
					} else if (OrderBaseOrderTypeDictEnum.ACTIVITY.getCode() == orderBase.getOrderType().intValue()) {
						params.put("userName", nick);
						params.put("title", orderBase.getTitle());
						smsBaseService.send(userIdentity.getIdentity(),
								SmsCfg.getInstance().getIntValue("sms.template.order.activityPayed", 1013), params);
					}
				}
			}
		}
	}

	@Override
	public void orderPayedToSender(String orderNo) {
		if (StringUtil.isBlank(orderNo)) {
			return;
		}
		OrderBase orderBase = orderBaseService.getByOrderNo(orderNo);
		if (orderBase == null) {
			return;
		}
		UserBase userBase = userBaseService.getById(orderBase.getBuyerId());
		if (userBase == null) {
			return;
		}
		UserIdentity userBuyerIdentity = new UserIdentity();
		userBuyerIdentity.setType(UserIdentityTypeDictEnum.PHONE.getCode());
		userBuyerIdentity.setUserId(orderBase.getBuyerId());
		userBuyerIdentity = userIdentityService.getOne(userBuyerIdentity);
		String buyerPhone = "(无)";
		if (userBuyerIdentity != null && UserIdentityTypeDictEnum.PHONE.getCode() == userBuyerIdentity.getType()) {
			buyerPhone = userBuyerIdentity.getIdentity();
		}
		String nick = "买家";
		if (StringUtil.isNotBlank(userBase.getNick())) {
			nick = userBase.getNick();
		}
		String orderTimeStr = TimeUtil.getStringTimeByFormat(orderBase.getNewAt(), "MM月dd日HH时mm分");
		// 短信通知给配送方接口人
		if (orderBase.getOrderType() != null
				&& OrderBaseOrderTypeDictEnum.QSHOP.getCode() == orderBase.getOrderType().intValue()) {
			Map<String, String> paramsCharge = new HashMap<String, String>();
			OrderDelivery orderDelivery = orderDeliveryService.getByOrderNoAndType(orderNo,
					OrderDeliveryTypeDictEnum.SELLERSEND.getCode());
			if (orderDelivery == null) {
				orderDelivery = orderDeliveryService.getByOrderNo(orderNo);
			}
			String tips = "";
			if (orderDelivery != null) {
				if (orderDelivery.getType() != null
						&& OrderDeliveryTypeDictEnum.BUYERPICKUP.getCode() == orderDelivery.getType().intValue()) {
					tips = "(自提)";
				}
				paramsCharge.put("userInfo", "(" + nick + "," + buyerPhone + "," + orderDelivery.getAddress() + ")");
			} else {
				paramsCharge.put("userInfo", "(" + nick + "," + buyerPhone + ")");
			}
			paramsCharge.put("orderTime", orderTimeStr);
			paramsCharge.put("bizzType", "社区");
			paramsCharge.put("bizzContent", "(" + orderBase.getTitle() + ")" + tips);
			if (StringUtil.isBlank(tips)) {// 如果不是自提，则短信提醒配送方
				// 同时短信通知给配送方接口人
				SendDeliveryUserOrder sendDeliveryUserOrder = sendDeliveryUserOrderService.getByOrderNo(orderNo);
				if (sendDeliveryUserOrder != null) {
					UserIdentity userIdentity = new UserIdentity();
					userIdentity.setUserId(sendDeliveryUserOrder.getDeliveryUserId());
					userIdentity.setType(UserChannelEnum.PHONE.getCode());
					userIdentity = userIdentityService.getOne(userIdentity);
					if (userIdentity != null) {
						Map<String, String> map = this.getParamsByOrderNo(orderNo);
						Map<String, String> qqParams = new HashMap<String, String>();
						qqParams.put("userName", map.get("userName"));
						qqParams.put("receiveName", map.get("receiveName"));
						qqParams.put("receiveAddress", map.get("receiveAddress"));
						qqParams.put("timeStr", map.get("timeStr"));
						qqParams.put("shopName", map.get("shopName"));
						qqParams.put("productAndQuantity", map.get("productAndQuantity"));
						qqParams.put("note", map.get("note"));
						smsBaseService.send(userIdentity.getIdentity(),
								SmsCfg.getInstance().getIntValue("sms.template.order.newPayedOrBeDelivery", 1031),
								qqParams);
						/*
						 * smsBaseService.send(userIdentity.getIdentity(),
						 * SmsCfg.getInstance().getIntValue(
						 * "sms.template.order.notice.sendToCharge", 1025),
						 * paramsCharge);
						 */
					}
				}
			}
		}
	}

	@Override
	public void orderPayedToSuperSender(String orderNo) {
		if (StringUtil.isBlank(orderNo)) {
			return;
		}
		OrderBase orderBase = orderBaseService.getByOrderNo(orderNo);
		if (orderBase == null) {
			return;
		}
		UserBase userBase = userBaseService.getById(orderBase.getBuyerId());
		if (userBase == null) {
			return;
		}
		UserIdentity userBuyerIdentity = new UserIdentity();
		userBuyerIdentity.setType(UserIdentityTypeDictEnum.PHONE.getCode());
		userBuyerIdentity.setUserId(orderBase.getBuyerId());
		userBuyerIdentity = userIdentityService.getOne(userBuyerIdentity);
		String buyerPhone = "(无)";
		if (userBuyerIdentity != null && UserIdentityTypeDictEnum.PHONE.getCode() == userBuyerIdentity.getType()) {
			buyerPhone = userBuyerIdentity.getIdentity();
		}
		String nick = "买家";
		if (StringUtil.isNotBlank(userBase.getNick())) {
			nick = userBase.getNick();
		}
		String orderTimeStr = TimeUtil.getStringTimeByFormat(orderBase.getNewAt(), "MM月dd日HH时mm分");
		// 短信通知给配送方接口人
		if (orderBase.getOrderType() != null
				&& OrderBaseOrderTypeDictEnum.QSHOP.getCode() == orderBase.getOrderType().intValue()) {
			Map<String, String> paramsCharge = new HashMap<String, String>();
			OrderDelivery orderDelivery = orderDeliveryService.getByOrderNoAndType(orderNo,
					OrderDeliveryTypeDictEnum.SELLERSEND.getCode());
			if (orderDelivery == null) {
				orderDelivery = orderDeliveryService.getByOrderNo(orderNo);
			}
			String tips = "";
			if (orderDelivery != null) {
				if (orderDelivery.getType() != null
						&& OrderDeliveryTypeDictEnum.BUYERPICKUP.getCode() == orderDelivery.getType().intValue()) {
					tips = "(自提)";
				}
				paramsCharge.put("userInfo", "(" + nick + "," + buyerPhone + "," + orderDelivery.getAddress() + ")");
			} else {
				paramsCharge.put("userInfo", "(" + nick + "," + buyerPhone + ")");
			}
			paramsCharge.put("orderTime", orderTimeStr);
			paramsCharge.put("bizzType", "社区");
			paramsCharge.put("bizzContent", "(" + orderBase.getTitle() + ")" + tips);
			if (StringUtil.isBlank(tips)) {// 如果不是自提，则短信提醒
				// 短信通知给超级权限配送人
				SendDeliveryUser sendDeliveryUser = new SendDeliveryUser();
				sendDeliveryUser.setHasSuperPower(YesNoEnum.YES.getCode());
				List<SendDeliveryUser> listSendDeliveryUser = sendDeliveryUserService.queryList(sendDeliveryUser);
				if (listSendDeliveryUser != null && listSendDeliveryUser.size() > 0) {
					for (SendDeliveryUser sendDeliveryUser2 : listSendDeliveryUser) {
						UserIdentity identity = new UserIdentity();
						identity.setUserId(sendDeliveryUser2.getUserId());
						identity.setType(UserIdentityTypeDictEnum.PHONE.getCode());
						List<UserIdentity> listUserIdentity = userIdentityService.queryList(identity);
						if (listUserIdentity != null && listUserIdentity.size() > 0) {
							Map<String, String> map = this.getParamsByOrderNo(orderNo);
							for (UserIdentity userIdentity : listUserIdentity) {
								Map<String, String> qqParams = new HashMap<String, String>();
								qqParams.put("userName", map.get("userName"));
								qqParams.put("receiveName", map.get("receiveName"));
								qqParams.put("receiveAddress", map.get("receiveAddress"));
								qqParams.put("timeStr", map.get("timeStr"));
								qqParams.put("shopName", map.get("shopName"));
								qqParams.put("productAndQuantity", map.get("productAndQuantity"));
								qqParams.put("note", map.get("note"));
								smsBaseService.send(userIdentity.getIdentity(), SmsCfg.getInstance()
										.getIntValue("sms.template.order.newPayedOrBeDelivery", 1031), qqParams);
								/*
								 * smsBaseService.send(userIdentity.getIdentity(
								 * ), SmsCfg.getInstance() .getIntValue(
								 * "sms.template.order.notice.sendToCharge",
								 * 1025), paramsCharge);
								 */
							}
						}
					}
				}
			}
		}
	}

	@Override
	public void orderSelected(String orderNo) {
		if (StringUtil.isBlank(orderNo)) {
			return;
		}
		OrderBase orderBase = orderBaseService.getByOrderNo(orderNo);
		if (orderBase == null) {
			return;
		}
		UserBase userBase = userBaseService.getById(orderBase.getBuyerId());
		if (userBase == null) {
			return;
		}
		String nick = "买家";
		if (StringUtil.isNotBlank(userBase.getNick())) {
			nick = userBase.getNick();
		}
		String toShopPhone = getShopPhone(orderBase.getShopId());
		if (StringUtil.isNotBlank(toShopPhone)) {
			Map<String, String> params = new HashMap<String, String>();
			params.put("userName", nick);
			params.put("title", orderBase.getTitle());
			smsBaseService.send(toShopPhone, SmsCfg.getInstance().getIntValue("sms.template.order.selected", 1002),
					params);
		} else {
			OrderSplit orderSplit = new OrderSplit();
			orderSplit.setOrderNo(orderNo);
			List<OrderSplit> listOrderSplit = orderSplitService.queryList(orderSplit);
			if (listOrderSplit != null && listOrderSplit.size() > 0) {
				for (OrderSplit orderSplit2 : listOrderSplit) {
					if (orderSplit2.getSellerId() != null && orderSplit2.getSellerId().intValue() != 0) {
						UserIdentity userIdentity = new UserIdentity();
						userIdentity.setType(UserIdentityTypeDictEnum.PHONE.getCode());
						userIdentity.setUserId(orderSplit2.getSellerId());
						userIdentity = userIdentityService.getOne(userIdentity);
						if (userBase == null || userIdentity == null || (userIdentity.getType() != null
								&& UserIdentityTypeDictEnum.PHONE.getCode() != userIdentity.getType())) {
							continue;
						}
						Map<String, String> params = new HashMap<String, String>();
						params.put("userName", nick);
						params.put("title", orderBase.getTitle());
						smsBaseService.send(userIdentity.getIdentity(),
								SmsCfg.getInstance().getIntValue("sms.template.order.selected", 1002), params);
					}
				}
			}
		}
	}

	@Override
	public void toUserWhenDeliveryed(String orderNo, Integer deliveryUserId, Timestamp now) {
		String time = TimeUtil.getStringTimeByFormat(now, "MM月dd日HH时mm分");
		if (StringUtil.isBlank(time)) {
			return;
		}
		OrderBase orderBase = orderBaseService.getByOrderNo(orderNo);
		if (orderBase == null) {
			return;
		}
		if (orderBase.getBuyerId() == null || orderBase.getBuyerId().intValue() == 0) {
			return;
		}
		UserBase userBase = userBaseService.getById(orderBase.getBuyerId());
		if (userBase == null) {
			return;
		}
		// 找到买家电话
		UserIdentity buyerUserIdentity = new UserIdentity();
		buyerUserIdentity.setType(UserIdentityTypeDictEnum.PHONE.getCode());
		buyerUserIdentity.setUserId(orderBase.getBuyerId());
		buyerUserIdentity = userIdentityService.getOne(buyerUserIdentity);
		if (buyerUserIdentity == null) {
			return;
		}
		if (orderBase.getOrderType() != null
				&& OrderBaseOrderTypeDictEnum.QSHOP.getCode() == orderBase.getOrderType().intValue()) {
			Map<String, String> map = this.getParamsByOrderNo(orderNo);
			if (map != null) {
				Map<String, String> params = new HashMap<String, String>();
				params.put("shopName", map.get("shopName"));
				params.put("productAndQuantity", map.get("productAndQuantity"));
				smsBaseService.send(buyerUserIdentity.getIdentity(),
						SmsCfg.getInstance().getIntValue("sms.template.order.newSentToUser", 1035), params);
				String shopPhone = getShopPhone(orderBase.getShopId());
				if (StringUtil.isNotBlank(shopPhone)) {
					Map<String, String> shopParams = new HashMap<String, String>();
					shopParams.put("orderNo", map.get("orderNo"));
					smsBaseService.send(shopPhone,
							SmsCfg.getInstance().getIntValue("sms.template.order.newSentToSeller", 1032), shopParams);
				}
			}
		} else {
			String userName = userBase.getNick();
			UserAuth userAuth = userAuthService.getByUserId(deliveryUserId);
			if (userAuth != null) {
				userName = userAuth.getRealName();
			}
			UserIdentity userIdentity = new UserIdentity();
			userIdentity.setType(UserIdentityTypeDictEnum.PHONE.getCode());
			userIdentity.setUserId(deliveryUserId);
			userIdentity = userIdentityService.getOne(userIdentity);
			if (userIdentity == null) {
				return;
			}
			Map<String, String> params = new HashMap<String, String>();
			params.put("orderNo", orderNo);
			params.put("title", orderBase.getTitle());
			params.put("userName", userName);
			params.put("phone", userIdentity.getIdentity());
			params.put("time", time);
			smsBaseService.send(buyerUserIdentity.getIdentity(),
					SmsCfg.getInstance().getIntValue("sms.template.order.toUserWhenSent", 1027), params);
		}
	}
}